package org.hot100_3;

import java.util.HashSet;

public class leetcode128 {
    public int longestConsecutive(int[] nums) {

        int n = nums.length;

        HashSet<Integer> set = new HashSet<>();

        for (int num : nums) {
            set.add(num);
        }

        int max = 0;
        for (int i = 0; i < n; i++) {
            if (!set.contains(nums[i] - 1)) {
                int curr = 1;
                int j = 1;
                while (set.contains(nums[i] + j)) {
                    j++;
                    curr++;
                }
                max = Math.max(max, curr);
            }
        }

        return max;
    }
}
